package com.cqie.controller;

import com.cqie.dto.PrescriptionInfo.AddPrescriptionInfoDto;
import com.cqie.dto.PrescriptionInfo.PrescriptionInfoDto;
import com.cqie.entity.PrescriptionInfo;
import com.cqie.exception.SpecialException;
import com.cqie.service.IPrescriptionInfoService;
import com.cqie.util.ResultTemplate;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 处方信息 前端控制器
 * </p>
 *
 * @author 不吃海鲜
 * @since 2024-12-26
 */
@Tag(name = "处方管理Controller", description = "描述：处方接口")
@Slf4j
@RestController
@RequestMapping({"/api/v1.0/prescriptionInfo", "/api/v1/prescriptionInfo"})
public class PrescriptionInfoController {

    private final IPrescriptionInfoService prescriptionInfoService;

    public PrescriptionInfoController(IPrescriptionInfoService prescriptionInfoService) {
        this.prescriptionInfoService = prescriptionInfoService;
    }

    @Operation(summary = "新增处方信息")
    @PostMapping("/addPrescriptionInfo")
    public ResultTemplate<Boolean> addPrescriptionInfo(@RequestBody AddPrescriptionInfoDto addPrescriptionInfoDto) throws SpecialException {
        return ResultTemplate.Success(prescriptionInfoService.addPrescriptionInfo(addPrescriptionInfoDto));
    }

    @Operation(summary = "查看处方列表")
    @Parameters({
            @Parameter(name = "likeQuery", description = "模糊查询条件"),
            @Parameter(name = "isPay", description = "是否支付"),
            @Parameter(name = "pageSize", description = "分页大小"),
            @Parameter(name = "pageIndex", description = "当前页码")
    })
    @GetMapping("/getPrescriptionInfoList")
    public ResultTemplate<List<PrescriptionInfoDto>> getPrescriptionInfoList(
            @RequestParam(defaultValue = "", required = false) String likeQuery,
            @RequestParam(defaultValue = "", required = false) String isPay,
            @RequestParam(defaultValue = "6", required = false) Integer pageSize,
            @RequestParam(defaultValue = "1", required = false) Integer pageIndex) throws SpecialException {
        return ResultTemplate.Success(prescriptionInfoService.getPrescriptionInfoList(likeQuery, isPay, pageSize,
                pageIndex));
    }

    @Operation(summary = "根据病例编码查看处方信息")
    @Parameters({
            @Parameter(name = "caseCode", description = "病例编码", required = true)
    })
    @GetMapping("/getPrescriptionInfoByCaseCode")
    public ResultTemplate<PrescriptionInfo> getPrescriptionInfoByCaseCode(@RequestParam(required = true) String caseCode) throws SpecialException {
        return ResultTemplate.Success(prescriptionInfoService.getPrescriptionInfoByCaseCode(caseCode));
    }

    @Operation(summary = "根据处方编码删除处方信息")
    @Parameters({
            @Parameter(name = "prescriptionCode", description = "处方编码", required = true)
    })
    @GetMapping("/delPrescriptionInfo")
    public ResultTemplate<Boolean> delPrescriptionInfo(@RequestParam(required = true) String prescriptionCode) throws SpecialException {
        return ResultTemplate.Success(prescriptionInfoService.delPrescriptionInfo(prescriptionCode));
    }
}
